<?php

namespace app\v1\controller;

//use think\Controller;
use think\Request;
use app\v1\controller\Authorization;
use think\Validate;

/**
 * Class User
 * @package app\v1\controller
 * 账号模块控制器
 */
class User extends Authorization
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
    }

    //获取家长账号的孩子列表
    public function getChildList(){
        $parentId=input('userId',0,'intval');
        $user=model('v1/User');
        $user->getChildList($parentId);
    }

    //获取孩子的信息以及孩子的操作token
    public function getChildInfo(){
        $childId=input('childId',0,'intval');
        $parentId=input('userId',0,'intval');
        $orgId=input('orgId',0,'int');
        $shopId=input('shopId',0,'int');
        $user=model('v1/User');
        $user->getChildInfo($orgId,$shopId,$childId,$parentId);

    }

    //修改孩子资料信息
    public function editChildInfo(){
        $childName=input('childName',null);
        $sex=input('sex',0,'int');
        $idNum=input('idNum',null);
        $validate=new Validate([
            'childName'=>'require|max:20',
            'sex'=>'require|number|between:1,2',
            'idNum'=>'require|number|length:18'
        ]);
        $validate->message([
            'childName.require'=>'孩子名字不能为空',
            'childName.max'=>'孩子名字长度太长',
            'sex.require'=>'性别参数不能为空',
            'sex.number'=>'sex参数必须为整数',
            'sex.between'=>'sex参数值有误',
            'idNum.require'=>'身份证号码不能为空',
            'idNum.number'=>'性别参数有误',
            'idNum.length'=>'身份证号码格式错误'

        ]);
        $data=$this->request->post();
        if(!$validate->check($data)){
            renderInfo(400001,$validate->getError());
        }
        $user=model('v1/User');
        $user->editChildInfo($childName,$sex,$idNum);
    }
    //获取家长对应孩子的身份资料
    public function getChildData(){
        $user=model('v1/User');
        $user->getChildData();
    }

    //修改密码
    public function setPassword(){
        $oldPassword=input('oldPassword',null);
        $newPassword=input('newPassword',null);
        $validate=new Validate([
            'oldPassword'=>'require|min:6',
            'newPassword'=>'require|min:6'
        ]);
        $validate->message([
            'oldPassword.require'=>'请填写旧密码',
            'oldPassword.min'=>'密码最少为6位数',
            'newPassword.require'=>'请填写新密码',
            'newPassword.min'=>'密码至少为6位数'
        ]);
        $data=$this->request->post();
        if(!$validate->check($data)){
            renderInfo(400001,$validate->getError());
        }
        $user=model('v1/User');
        $user->setPassword($oldPassword,$newPassword);

    }

    //退出登录
    public function logout(){
        $user=model('v1/User');
        $user->logout();
    }

    //获取个人中心的信息
    public function userCenter(){
        $user=model('v1/User');
        $user->userCenter();
    }

    //获取机构列表
    public function getOrgList(){
        $childId=input('childId',0,'int');
        $user=model('v1/User');
        $user->getOrgList($childId);
    }

    //获取学校列表

    public function schoolList(){
        $orgId=input('orgId',0,'int');
        $user=model('v1/User');
        $user->schoolList();
    }

    //确定用当前微信绑定当前账号
    public function userBandingWeixin(){
        $user=model('v1/User');
        $redis=getRedis();
        $userInfo=getUserInfo();
        $openId=$redis->get('openId'.$userInfo['parentId']);

        $user->changeBinding($userInfo['parentId'],$openId);
    }






}
